package com.redis.springbootredis.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author
 * @create 2020-11-02 16:40
 */
//实现拦截器接口(HandlerInterceptor)
public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if(request.getSession().getAttribute("user") != null){
            return true;
        }
        request.getRequestDispatcher("/index.html").forward(request,response);
        return false;
    }
}
